package controller;

import information.AbstractInformation;

import javax.swing.JPanel;

import table.AbstractTable;



public abstract class AbstractController extends JPanel{


	private static final long serialVersionUID = 1L;
	
	private JPanel informationPane;
	
	private AbstractTable currentView;
	private AbstractInformation currentInformation;

	public AbstractController(JPanel informationPane) {
		this.informationPane = informationPane;
	}
	
	public void select(AbstractTable view, AbstractInformation information) {
		deselect();
		
		if (view != null && currentView != view) {
			currentView = view;
			currentView.activate();
		}

		if (information != null && currentInformation != information) {
			currentInformation = information;
			
			informationPane.add(information);
			informationPane.repaint();
		}
	}
	
	public void deselect() {
		if (currentView != null) {
			currentView.deactivate();
			currentView = null;
		}
		
		if (currentInformation != null) {
			currentInformation.clear();
			currentInformation = null;
		}
		
		informationPane.removeAll();
		informationPane.repaint();
	}
	
	public AbstractTable getCurrentView() {
		return currentView;
	}
	
	public AbstractInformation getCurrentInformation() {
		return currentInformation;
	}
	
	
}
